$(function () {
   var modifyurl = '/person/retrieve';
   var sendcodeurl = '/person/sendPhoneCode';

   //点击发送验证码到指定邮箱中
   $('#getcode').click(function () {
       var phone = $('#phone').val();
       if (!phone){
           $.toast('请输入手机号');
       } else {
           sendcodeurl = sendcodeurl+'?type=retrieve&phone='+phone;
           time(this);
           $.getJSON(sendcodeurl,function (data) {
               $.toast(data.message);
           })
       }
   });


    //提交信息
    $('#submit').click(function () {
        //获取手机号、手机验证码、两次输入的密码以及验证码(先判断两次输入的密码是否一致)
        var password1 = $('#password1').val();
        var password2 = $('#password2').val();
        var phoneCode = $('#phoneCode').val();
        var code = $('#j_captcha').val();
        var phone = $('#phone').val();
        if (password1 == '' || password2 == '' || phoneCode == '' || code == '' || phone == '') {
            $.toast('输入的信息不全');
        }else if (password1 != password2) {
            $.toast('两次输入的密码不一致');
        }else{
            var formData = new FormData();
            formData.append('phone',phone);
            formData.append('password',password1);
            formData.append('code',code);
            formData.append('phoneCode',phoneCode);
            $.ajax({
                url:modifyurl,
                type:"POST",
                data:formData,
                contentType:false,
                processData:false,
                cache:false,
                success:function (data) {
                    $.toast(data.message);
                    if (data.success) {
                        //修改成功,跳转到登录界面
                        window.location.href = "/login";
                    }
                }
            })
        }

        //     var personInfo = {};
        //     personInfo.mail=$('#mail').val();
        //     personInfo.password=password1;
        //     personInfo.vcode = $('#mail_code').val();
        //     var formData = new FormData();
        //     formData.append('personInfoStr',JSON.stringify(personInfo));
        //     $.ajax({
        //         url:modifyurl,
        //         type:'POST',
        //         data:formData,
        //         contentType : false,
        //         processData : false,
        //         cache : false,
        //         success:function (data) {
        //             $.toast(data.errMsg);
        //         }
        //     })
        // }else {
        //     $.toast('填写的信息不规范');
        //     return;
        // }

    });



    var wait=60;
    function time(o) {
        if (wait == 0) {
            o.removeAttribute("disabled");
            o.value="免费获取验证码";
            wait = 60;
        } else {
            o.setAttribute("disabled", true);
            o.value=wait+"秒后可以重新发送";
            wait--;
            setTimeout(function() {
                    time(o)
                },
                1000)
        }
    }

});
